﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows;
using System.Windows.Controls;
using FinPlusInterfaces;
using FinPlusAssembler;

namespace FinPlusCompView
{
    public class ColHelper
    {
        public string Name { get; private set; }
        public string LinkedId { get; private set; }
        public CheckBox FilterCheck { get; private set; }
        public string ColType, Links, StringFormat, InputMask, Type, Value;
        public bool IsEnabled;

        private const double _defaultColWidth = 70;

        //construct
        public ColHelper(string name, string linkedId, RoutedEventHandler filterbarAdd, RoutedEventHandler filterbarRemove, string colType = "ValueFormat", string type = "String")
        {
            Name = name;
            LinkedId = linkedId;
            ColType = colType;
            Type = type;
            Links = StringFormat = InputMask = Value = string.Empty;

            FilterCheck = new CheckBox() { Content = name, Tag = name, FlowDirection = FlowDirection.RightToLeft };
            FilterCheck.Checked += filterbarAdd;
            FilterCheck.Unchecked += filterbarRemove;
        }

        //public
        public DataGridTemplateColumn GetTemplate(DependencyProperty tag, string name)
        {
            DataGridTemplateColumn col = null;
            
            switch(ColType.EnumParse<ColumnType>(ColumnType.ValueFormat))
            {
                case ColumnType.Exclude: return  null;  
                case ColumnType.ValueChange: col = new FinPlusGridColChange(Name, StringFormat, IsEnabled); break; 
                case ColumnType.CheckBox: col = new FinPlusGridColCheckBox(Name, FilterCheck, IsEnabled); break; 
                case ColumnType.ComboLink: col = new FinPlusGridColComboBox(Name, Links, FilterCheck, IsEnabled); break; 
                case ColumnType.PodEditPopup: col = new FinPlusGridColEditorPopup(Name, Links, IsEnabled); break; 
                case ColumnType.ValueFormat: col = new FinPlusGridColFormat(Name, StringFormat, InputMask, Type, FilterCheck, false, IsEnabled); break; 
                case ColumnType.ValuePod: col = new FinPlusGridColPod(Name, IsEnabled); break; 
                case ColumnType.ValueOnOff: col = new FinPlusGridColOnOff(Name, FilterCheck, IsEnabled); break; 
                case ColumnType.QuoteHit: col = new FinPlusGridColQuoteHit(Name, StringFormat, Links, LinkedId, IsEnabled); break; 
                case ColumnType.QuotePopup: col = new FinPlusGridColQuotePopup(Name, Links, IsEnabled); break; 
                case ColumnType.SelectLink: col = new FinPlusGridColSelectBox(Name, Links, FilterCheck, IsEnabled); break; 
                case ColumnType.ValueShift: col = new FinPlusGridColShift(Name, StringFormat, Links, InputMask, IsEnabled); break; 
                case ColumnType.ValueTriState: col = new FinPlusGridColTriState(Name, FilterCheck, false, IsEnabled); break; 
            }

            col.SetValue(tag, name);
            col.Width = _defaultColWidth;

            return col;
        }
    }
}
